package com.thewaybetter.modules.client.pages;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class HomePage {

	final Button btnNewIdea = new Button("New Idea");
	final TextBox txtTitle = new TextBox();
	final TextArea txaIdea = new TextArea();
	final TextBox txtEmail = new TextBox();
	final DialogBox dlgNewIdea = new DialogBox();
	
	public HomePage() {
		configureWidgets();
		configurePanels();
		configureButtons();
	}
	
	
	public void drawPage(){
		RootPanel.get().add(btnNewIdea);
	}
	
	private void configureWidgets(){
		dlgNewIdea.setText("Define your idea");
		dlgNewIdea.setAnimationEnabled(true);
		txaIdea.setSize("300","150");
		txtTitle.setWidth("300");
		txtEmail.setWidth("300");
	}
	
	private void configurePanels(){
		VerticalPanel vp = new VerticalPanel();
		vp.setTitle("Define your idea");
		vp.add(new Label("Your title: "));
		vp.add(txtTitle);
		vp.add(new Label("Your idea:"));
		vp.add(txaIdea);
		vp.add(new Label("Your email:"));
		vp.add(txtEmail);
		final HorizontalPanel hp = new HorizontalPanel();
		final Button btnSend = new Button("Save your idea");
		hp.add(btnSend);
		hp.setCellHorizontalAlignment(btnSend, HasHorizontalAlignment.ALIGN_RIGHT);
		vp.add(hp);
		dlgNewIdea.setWidget(vp);
	}
	
	private void configureButtons(){
		btnNewIdea.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				showDialog();
			}
		});
	}
	
	private void showDialog(){
		dlgNewIdea.show();
	}
	
}
